home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 966 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.9 KB

  1. From: abell@mindspring.com (Andrew Bell)
  2. Message-ID: <4jvcrn$ch2@mule1.mindspring.com>
  3. X-Original-Date: Thu, 04 Apr 1996 02:43:24 GMT
  4. Path: in2.uu.net!bounce-back
  5. Date: 05 Apr 96 02:53:49 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: constness of private members and methods
  9. Organization: MindSpring Enterprises
  10. References: <m0u3992-000GcEC@7.kurahaupo.gen.nz> <3161eaa4.8216104@nntp.ix.netcom.com>
  11. X-Newsreader: Forte Agent .99.82
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMWSLSeEDnX0m9pzZAQFk7AGAkXlAmMvjma54SnOAINpJPUwMFwttp5EJ
  14.     8CNH9t10WLmyxk/4MXvvIYx/1oMqwnx1
  15.     =X2Ju
  16.  
  17. jdmorris@ix.netcom.com (Jason D. Morris) wrote:
  18. >Assuming you allow 'pure' and 'clean', the compiler would then have
  19. >to check to make sure your functions were in fact 'pure' and 'clean'.
  20. >If the compiler could do such checking as part of its array of
  21. >optimizations, why not just do it for every function as
  22. >part of a general optimization step?
  23.  
  24. The problem is the compiler needs to know the "purity" of the
  25. functions a given function calls during its compilation, or it can't
  26. optimize the code.  You would thus have to compile all the called
  27. functions first, and have that information available while  you
  28. compile that given function. For reasons I hope are reasonably
  29. obvious, this is impossible.  Conceivably you could have a compilation
  30. system that does a first pass compilation over all of the code,
  31. looking for purity of functions, and then a second pass to do the
  32. actual compilation, but that's a bit beyond the capabilities of most
  33. modern compilers...
  34.  
  35. With the proposed idea, a function that claims to pure and isn't would
  36. be tagged with a compiler error.  This might be problematic with
  37. templates, as instantiation for a particular type may lead to non-pure
  38. functions being called.  Also, changing a function so that it is no
  39. longer pure may lead to a cascade of changes to other functions, as
  40. they would lose their purity tag.  There are probably some other
  41. problems I may not have noticed also (libraries that depend on other,
  42. canging, libraries?)
  43.  
  44. Before making this part of the standard, it would be nice to have some
  45. sample evidence of how much of a performance difference it makes in
  46. meaningful programs.  In general, you can simulate this by saving in a
  47. variable what you would use multiple calls to get (this is not as nice
  48. for normal programming as having tags, however, as it would require
  49. substantially more work to change if the called function is no longer
  50. pure, or (even worse) might not get changed when it needs to be. 
  51.  
  52. Andrew Bell
  53. abell@mindspring.com
  54. ---
  55. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  56. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  57. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  58. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  59. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  60.